﻿using System;
using System.Web.Mvc;
using doufu.Common;
using doufu.Model;

namespace doufu.WebUI.Controllers
{
    public class ToolsController : BaseController
    {
        [UserAuthorize]
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        [ValidateInput(false)]
        [UserAuthorize]
        public ActionResult Index(string TSQL)
        {
            if (string.IsNullOrWhiteSpace(TSQL))
            {
                return View((object)"SQL 不能为空！");
            }
            try
            {
                return View(Services.Tools.Excute(TSQL));
            }
            catch (Exception e)
            {
                return View(e);
            }
        }

        [HttpPost]
        public ActionResult Excute(string sql)
        {
            Services.Tools.Excute(sql);
            return Content("1");
        }

        //[UserAuthorize]
        public ActionResult TestServer()
        {
            return View();
        }

        public ActionResult TestSQLite()
        {
            return View();
        }

        public ActionResult Table(string table)
        {
            if (table.IsNullOrEmpty())
                return View(new TableInfo { columns_array = "[]" });
            return View(Services.Tools.GetTableInfo(table));
        }

    }
}
